using System;
using System.Collections.Generic;
using System.Text;

namespace Scheduler
{
    public class User
    {
        String userID;
        String password;
        int type;//0->admin, 1->rmt, 2-> customer

        public User()
        {
            userID = "";
            password = "";
            type = -1;
        }
        public User(String userID, String password, int type)
        {
            this.userID = userID;
            this.password = password;
            this.type = type;
        }
        public void writeToDatabase(Database db)
        {
            db.writeUser(userID, password, type);
        }

        /*
         * Checks the login information provided by this User with the
         * one in the database. Returns true if equal and false otherwise.
         */ 
        public Boolean login(Database db)
        {
            User temp = db.readUser(userID);
            if (temp != null)
            {
                if (this.Equals((object) this) && temp.password == password)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return false;
        }
        public override bool Equals(object obj)
        {
            if (obj is User)
            {
                return (String.Compare(this.userID, ((User)obj).userID, true) == 0 &&
                        this.type == ((User)obj).type);
            }
            else
            {
                return false;
            }
        }
        /*
         * Queries the database to get a list of all the users with a certain type.
         * Returned LinkedList of contains their IDs.
         */ 
        public static LinkedList<User> getAllUsers(Database db, int type)
        {
            return db.readAllUsers(type);
        }

    }
}
